import request from '@/utils/request'
import { ApiModulesRoutes } from '@/consts'

/**
 *
 * @param paramVo
 * @return {Promise<void>}
 */
export const apiFindTaskPageByParam = async(paramVo) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/findTaskPageByParam'
  return await request.post(url, paramVo)
}

/**
 * 删除算法任务
 * @param taskId
 * @return {Promise<AxiosResponse<any>>}
 */
export const apiDelAlgTaskById = async(taskId) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/delAlgTaskById'
  return await request.get(url, { params: { taskId } })
}

/**
 * 修改算法任务
 */
export const apiUpdateAlgTask = async(task) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/updateAlgTask'
  return await request.post(url, task)
}

/**
 * 查询算法任务
 * @param {String} taskId 算法任务id
 * @return {Promise<AxiosResponse<any>>}
 */
export const apiFindAlgTaskById = async(taskId) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/findAlgTaskById'
  return await request.get(url, { params: { taskId } })
}

/**
 * 分页查询任务下的设备
 * @param params
 * @param params.keyword
 * @param params.pageNo
 * @param params.pageSize
 * @param params.taskId
 * @return {Promise<AxiosResponse<any>>}
 */
export const apiFindTaskDevice = async(params) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/findTaskDevice'
  return await request.post(url, params)
}

/**
 * 批量新增算法任务的设备
 * @param {Array} deviceList
 * @param {String} deviceList.id 设备id
 * @param {String} deviceList.taskIdd 任务id
 * @return {Promise<void>}
 */
export const apiAddTaskDeviceBatch = async(deviceList) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/device/addTaskDeviceBatch'
  return await request.post(url, deviceList)
}

/**
 * 开启算法任务
 * @param {String} abilityDeviceId 设备代码
 */
export const apiStartTask = async(abilityDeviceId) => {
  const url = ApiModulesRoutes.BASE + '/alg/ability/device/startTask'
  return await request.get(url, { params: { abilityDeviceId } })
}
/**
 * 停止算法任务
 * @param {String} abilityDeviceId
 */
export const apiStopTask = async(abilityDeviceId) => {
  const url = ApiModulesRoutes.BASE + '/alg/ability/device/stopTask'
  return await request.get(url, { params: { abilityDeviceId } })
}

export const apiDelTaskDeviceBatch = async(deviceIdList) => {
  const url = ApiModulesRoutes.BASE + '/alg/task/device/delTaskDeviceBatch'
  return await request.post(url, deviceIdList)
}

/**
 * 批量添加算法对应的设备
 * @param {Array} abilityDeviceIDList
 * @param abilityDeviceIDList.abilityId
 * @param abilityDeviceIDList.deviceId
 * @return {Promise<void>}
 */
export const apiAddAbilityBatch = async(abilityDeviceIDList) => {
  const url = ApiModulesRoutes.BASE + '/alg/ability/device/addAbilityDeviceBatch'
  return await request.post(url, abilityDeviceIDList)
}

/**
 * 分页查找算法绑定的设备
 * @param params
 * @return {Promise<AxiosResponse<any>>}
 */
export const apiFindDevicePageByParam = async(params) => {
  const url = ApiModulesRoutes.BASE + '/alg/ability/device/findDevicePageByParam'
  return await request.post(url, params)
}

/**
 * 设备与算法解绑
 * @param abilityId 算法id
 * @param deviceId 设备id
 * @return {Promise<AxiosResponse<any>>}
 */
export const apiDelAbilityDeiceByAbilityId = async(abilityId, deviceId) => {
  const url = ApiModulesRoutes.BASE + '/alg/ability/device/delAbilityDeviceByAbilityId'
  return await request.get(url, { params: { abilityId, deviceId } })
}

/**
 * 批量删除算法对应的设备
 * @param {Array} abilityDeviceIds records.id
 * @return {Promise<void>}
 */
export const apiDelAbilityDeviceBatch = async(abilityDeviceIds) => {
  const url = ApiModulesRoutes.BASE + '/alg/ability/device/delAbilityDeviceBatch'
  return await request.post(url, abilityDeviceIds)
}
